import {
	objDeepCopy,
	getDateString
} from "@/assets/js/common.js";
import commonObject from "@/assets/js/xm.js";
let Controller = {
	created() {
		this.init();
	},
	mounted() {
		
	},
	methods: {
		init() {
			this.Model.whWarehouseId = this.$route.query.id; //id
			this.getDetailList(this,this.$route.query.id);
		},
		//获取详情列表
		getDetailList(that,whWarehouseId){
			var apiTest = this.apiTest;
			this.$ajax({
				method: 'post',
				url: apiTest + '/supplier/whWarehouse/materialsDetail',
				// url: '/api/supplier/whWarehouse/materialsDetail',
				data: {
					whWarehouseId:whWarehouseId
				}
			}).then((res) => {
				var data = res.data;
				that.Model.tab1TableData = [];
				if (data.status == 200) {
					var result = data.result;
					var obj;
					/* var pagination = commonObject.paginationFunction(data.result);
					that.Model.paginationObject = objDeepCopy(pagination); */
					if(result){
						// 信息
						that.Model.tableFormInline = [
							{
								label:'退料单号',
								value:result.number
							},
							{
								label:'单据状态',
								value:result.statusDict.value
							},
							{
								label:'单据类型',
								value:result.typeDict.value
							},
							{
								label:'供应商',
								value:result.supplierName
							},
							{
								label:'创建人',
								value:result.createBy
							}
						]
						//表格
						var whWarehouseDetails = result.whWarehouseDetails;
						for (let i = 0; i < whWarehouseDetails.length; i++) {
							obj = objDeepCopy(whWarehouseDetails[i]);
							that.Model.tab1TableData.push(obj)
						}
					}
			
				} else {
					that.tips(that, 'warning', data.msg);
				}
			
			});
		},
		
		
		
		//返回上一级列表
		back() {
			this.$router.push({
				path: 'returnList'
			})
		},
		selectedHighlight(data) {
			// 如果选中则添加高亮样式
			if (this.Model.TableSelectData.indexOf(data.row) > -1) {
				return {
					"background-color": "#FEF6EE"
				};
				return {}
			}
		},
		warehousing(row) {
			this.Model.warehousingDialogStatus = row.status;
			this.Model.warehousingDialogFlag = true;
		},
		handleSelectionChange(val) {
			console.log(val);
			this.Model.addGiftsSelectData = val

		},
		handleCurrentChange(val) {
			this.Model.pager.params.pageIndex = val;
		},
		handleSizeChange(val) {
			this.Model.pager.params.pageSize = val;
		},
		cardClick(color) {
			this.Model.cardSelected = color;
		},
		showChild(val) {
			this.Model.searchFromData = val;
		},
		toSearch(val) {
			console.log(val)
		},
		toClear(val) {
			this.Model.searchFromData = this.Model.defaultSearchFromData;
		},
		toExport(val) {
			console.log(val);
		},
		onTabChange(val) {
			console.log(val, this.Model.activeTab)
			switch (val) {
				case 1:
					break;
				case 2:
					break;
				case 3:
					break;
			}
		},
		toggleTableDetail(val) {
			
		},
		onDialogEdit(flag, val) {
			
		},
		tips(that, type, message) {
			let duration;
			type == 'success' ? duration = 3000 : duration = 10000;
			that.$message({
				message: message,
				type: type,
				duration: duration
			});
		},
	},
	watch: {
		//
		$route: {
			handler(newValue, oldValue) {
				if (newValue.query.id) {
					this.getDetailList(this, newValue.query.id);
					this.Model.whWarehouseId = newValue.query.id;
				}
			},
			deep: true
		},

	},
	filters: {
		shippingMethodFilters: function(value) {
			var val;
			value == '0' ? val = '快递' : val = '自提';
			return val;
		},
		
	}
}
export default Controller;
